parameters:
  buildConfig: ''                 # required -- build configuration
  archType: ''                    # required -- targeting CPU architecture
  osGroup: ''                     # required -- operating system for the job
  osSubgroup: ''                  # optional -- operating system subgroup
  condition: true
  pool: ''
  timeoutInMinutes: 240           # build timeout
  variables: {}
  helixQueues: ''
  runJobTemplate: '/eng/pipelines/coreclr/templates/run-superpmi-diffs-job.yml'
  diffType: 'asmdiffs'            # required -- 'asmdiffs', 'tpdiff', or 'all'
  baseJitOptions: ''              # e.g. JitStressModeNames=STRESS_PHYSICAL_PROMOTION;JitFullyInt=1
  diffJitOptions: ''

jobs:
- template: ${{ parameters.runJobTemplate }}
  parameters:
    jobName: ${{ format('superpmi_diffs_{0}_{1}{2}_{3}', parameters.diffType, parameters.osGroup, parameters.osSubgroup, parameters.archType) }}
    displayName: ${{ format('SuperPMI {0} {1}{2} {3}', parameters.diffType, parameters.osGroup, parameters.osSubgroup, parameters.archType) }}
    pool: ${{ parameters.pool }}
    buildConfig: ${{ parameters.buildConfig }}
    archType: ${{ parameters.archType }}
    osGroup: ${{ parameters.osGroup }}
    osSubgroup: ${{ parameters.osSubgroup }}
    condition: ${{ parameters.condition }}
    timeoutInMinutes: ${{ parameters.timeoutInMinutes }}
    helixQueues: ${{ parameters.helixQueues }}
    diffType: ${{ parameters.diffType }}
    baseJitOptions: ${{ parameters.baseJitOptions }}
    diffJitOptions: ${{ parameters.diffJitOptions }}
    dependsOn:
      - ${{ if in(parameters.diffType, 'asmdiffs', 'all') }}:
        - 'build_${{ parameters.osGroup }}${{ parameters.osSubgroup }}_${{ parameters.archType }}_checked_'
      - ${{ if in(parameters.diffType, 'tpdiff', 'all') }}:
        - 'build_${{ parameters.osGroup }}${{ parameters.osSubgroup }}_${{ parameters.archType }}_release_'

    variables:
    - ${{ each variable in parameters.variables }}:
      - ${{insert}}: ${{ variable }}

    - ${{ if in(parameters.diffType, 'tpdiff', 'all') }}:
      - ${{ if eq(parameters.osGroup, 'windows') }}:
        - name: releaseProductRootFolderPath
          value: '$(Build.SourcesDirectory)\artifacts\bin\coreclr\$(osGroup).$(archType).Release'
      - ${{ if ne(parameters.osGroup, 'windows') }}:
        - name: releaseProductRootFolderPath
          value: '$(Build.SourcesDirectory)/artifacts/bin/coreclr/$(osGroup).$(archType).Release'

    steps:

    - ${{ if in(parameters.diffType, 'asmdiffs', 'all') }}:
      # Download jit checked builds
      - template: /eng/pipelines/common/download-artifact-step.yml
        parameters:
          unpackFolder: $(Build.SourcesDirectory)/artifacts/bin/coreclr
          artifactFileName: 'CheckedJIT_$(osGroup)$(osSubgroup)_$(archType)$(archiveExtension)'
          artifactName: 'CheckedJIT_$(osGroup)$(osSubgroup)_$(archType)'
          displayName: 'JIT checked build'
          cleanUnpackFolder: false

    - ${{ if in(parameters.diffType, 'tpdiff', 'all') }}:
      # Download jit release builds
      - template: /eng/pipelines/common/download-artifact-step.yml
        parameters:
          unpackFolder: $(Build.SourcesDirectory)/artifacts/bin/coreclr
          artifactFileName: 'ReleaseJIT_$(osGroup)$(osSubgroup)_$(archType)$(archiveExtension)'
          artifactName: 'ReleaseJIT_$(osGroup)$(osSubgroup)_$(archType)'
          displayName: 'JIT release build'
          cleanUnpackFolder: false
